package com.objetdirect.gwt.umldrawer.client;

import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.Position;
import com.gwtext.client.data.SimpleStore;
import com.gwtext.client.data.Store;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.MessageBox;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.layout.FitLayout;

public class AddMemberWindow extends Window {

	public AddMemberWindow() {

		this.setTitle("Add New Member");
		this.setWidth(500);
		this.setHeight(150);
		this.setLayout(new FitLayout());
		this.setPaddings(5);
		this.setButtonAlign(Position.CENTER);

		Button sendButton = new Button("Add Member");
		this.addButton(sendButton);

		ButtonListenerAdapter sendButtonAdapter = new ButtonListenerAdapter() {
			@Override
			public void onClick(Button button, EventObject e) {
				MessageBox.alert("Server Info",
						"That Person Is Now A Member In That Project");
				hide();
			}
		};
		sendButton.addListener(sendButtonAdapter);

		Button cancelButton = new Button("Cancel");
		this.addButton(cancelButton);

		ButtonListenerAdapter cancelButtonAdapter = new ButtonListenerAdapter() {
			@Override
			public void onClick(Button button, EventObject e) {
				hide();
			}
		};
		cancelButton.addListener(cancelButtonAdapter);

		this.setCloseAction(Window.HIDE);
		this.setPlain(true);
		this.setModal(true);

		FormPanel formPanel = new FormPanel();
		formPanel.setBaseCls("x-plain");
		formPanel.setLabelWidth(100);
		formPanel.setUrl("save-form.php");

		formPanel.setWidth(500);
		formPanel.setHeight(100);

		formPanel.add(new TextField("Member E-Mail", "e-mail", 300));

		final Store store = new SimpleStore(new String[] {"privilege"}, getStates());
		store.load();

		ComboBox privilege = new ComboBox("Member Privilege", "privilage", 300);
		privilege.setEmptyText("Privilege");
		privilege.setForceSelection(true);
		privilege.setDisplayField("privilege");
		privilege.setMode(ComboBox.LOCAL);
		privilege.setTriggerAction(ComboBox.ALL);
		privilege.setTypeAhead(true);
		privilege.setSelectOnFocus(true);
		privilege.setStore(store);
		formPanel.add(privilege);

		this.add(formPanel);
		this.show();
	}

	private static String[][] getStates() {  
		         return new String[][]{  
		                 new String[]{"Read Only"},
		                 new String[]{"Read / Write"}
		                 };
	  }
}
